<?php
	include_once 'header.php';
	$gid = isset($_GET['gid']) && !empty($_GET['gid']) ? $_GET['gid'] : '1';
	
	$stmt = $pdo->prepare("select gid,gname,gphoto,price,num,zkprice,newdate
,IFNULL((SELECT sum(num) FROM kp_sell WHERE gid = ? ),0.00) allsell
,IFNULL((SELECT sum(num) FROM kp_sell WHERE gid = ? and sid LIKE DATE_FORMAT(NOW(), '%%%Y%m%%')),0.00) monthsell
from kp_goods where gid = ?");
	$stmt->execute(array($gid,$gid,$gid));
	$arrGood = $stmt->fetch(PDO::FETCH_ASSOC);
	//print_r($arrGood);
	
	$stmt = $pdo->prepare('select d.uname,a.gid,b.evaluate,evaldate from kp_goods a left join kp_sell b on a.gid = b.gid left join kp_sell_order c on b.sid = c.sid left join kp_usr d on c.uid = d.uid where a.gid=? and (b.evaluate is not null or b.evaluate = \'\') order by b.evaldate desc limit 500');
	$stmt->execute(array($gid));
	$arrEs = $stmt->fetchAll(PDO::FETCH_ASSOC);
	//print_r($arrEs)
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>商品详情页</title>
		<link rel="stylesheet" type="text/css" href="css/info.css"/>
		<script src="js/jquery-3.1.1.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/info.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div class="info">
			<?php
			if(!empty($arrGood)){
			 ?>
			<h1><?php echo $arrGood['gname'];?></h1>
			<hr />
			<div class="left">
				<?php
					$gphotos = [];
					if(!empty($arrGood['gphoto'])){
						$gphotos = explode(';', $arrGood['gphoto']);
					}
				
				 ?>
				
				
				<img class="bigimg" src="<?php if(!empty($gphotos[0])) echo  $gphotos[0]; else echo 'upload/good_001.gif'; ?>"/>
				<ul class="ul1">
					<li class="toleft" style="">&lt;</li>
					<div class="minimgs">
					<ul>
						<?php 
							foreach($gphotos as $gphoto){
								echo '<li><img src="'.$gphoto.'"/></li>';
							}
						?>
						<!--<li><img src="images/show1.jpg"/></li>
						
						<li><img src="images/show2.jpg"/></li>
						<li><img src="images/show3.jpg"/></li>
						<li><img src="images/show4.jpg"/></li>
						<li><img src="images/show5.jpg"/></li>
						<li><img src="images/show5.jpg"/></li>
						<li><img src="images/show5.jpg"/></li>-->
						
					</ul>
					</div>
					<li class="toright" style="">&gt;</li>
				</ul>
				<ul class="ul2">
					<li><img src="images/share.gif"/></li>
					<li class="right"><img src="images/favthis.gif"/></li>
				</ul>
			</div>
			<div class="right">
				<ul>
					<li>折扣价:   <?php echo $arrGood['zkprice'];?>元</li>
					<li>运    费:   免运费</li>
					
					<li>数量:<input type="number" name="goodnum" id="goodnum" style="width: 30px;" value="1" /></li>
					<li class="incar"><?php if($uid == 0) echo '<a href="login.php">请登陆</a>'; else echo '<a href="javascript:incar(\''.$arrGood['gid'].'\',\''.$uid.'\',document.querySelector(\'#goodnum\').value)">加入购物车</a>' ?></li>
					<!--<li class="bt"><img src="images/buynow.gif"/></li>-->
					<li class="gui">此商品支持网银支付，网上汇款免手续费。<br />收货满意后出售者才能拿钱，货款都安全！</li>
					
					<li>本期售出：<?php echo (int)$arrGood['monthsell'];?> 件</li>
					<li>累计售出：<?php echo (int)$arrGood['allsell'];?> 件</li>
					<li class="fl">商品类型：全新</li>
					<li class="fl">所 在 地：中国</li>
					<li class="fl">商品数量：<?php echo (int)$arrGood['num'];?> 件</li>
					<li class="fl">浏 览 量：999次</li>
				</ul>
				
			</div>
			<?php } ?>
			<div class="evaluate">
			<h3>用户评价:</h3>
			<?php 
				foreach($arrEs as $es){
			?>
			<ul>
				<li class="c1"><?php echo $es['uname'].'['.$es['evaldate'].']: '.$es['evaluate']; ?></li>
			</ul>
			<?php } ?>
			
			</div>
		</div>
		
		
		<?php include_once 'bottom.php'; ?>
	</body>
</html>
